package uml.behavioral.state;

/**
 * 状态--环境类<br>
 * on 2023/1/6 0:15
 */
public class Account {
    private AccountState state;
    private String owner;
    private double balance;

    public Account(String owner, double balance) {
        this.owner = owner;
        this.balance = balance;
        new NormalState(this);
        System.out.println(this.owner + "新开户，余额为" + this.balance);
        System.out.println("-----------------------");
    }

    public void setState(AccountState state) {
        this.state = state;
    }

    public AccountState getState() {
        return state;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public void withdraw(double amount) {
        System.out.println(this.owner + "取款" + amount);
        this.state.withdraw(amount);
        System.out.println("现在余额为：" + this.balance);
        System.out.println("账户状态为：" + this.state.getClass().getSimpleName());
        System.out.println("--------------------------");
    }

    public void deposit(double amount) {
        System.out.println(this.owner + "存款" + amount);
        this.state.deposit(amount);
        System.out.println("现在余额为：" + this.balance);
        System.out.println("账户状态为：" + this.state.getClass().getSimpleName());
        System.out.println("--------------------------");
    }

    public void computeInterest() {
        this.state.computeInterest();
        System.out.println("--------------------------");
    }
}
